//
//  YBMeiTuanRefreshView.swift
//  Weibo
//
//  Created by yinbo on 2018/4/8.
//  Copyright © 2018年 yinbo. All rights reserved.
//

import UIKit

class YBMeiTuanRefreshView: YBRefreshView {

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    
    @IBOutlet weak var buildingIconView: UIImageView!
    
    @IBOutlet weak var earthIconView: UIImageView!
    
    @IBOutlet weak var kangarooView: UIImageView!
    var parentViewHeight:CGFloat = 0.0{
        didSet{
//            print("父视图高度\(parentViewHeight)")
            if parentViewHeight < 23{
                return
            }
            var scale:CGFloat
            if parentViewHeight>160{
                scale = 1
            }
            else{
                scale = 1-(160-parentViewHeight)/(160-23)
            }
            kangarooView.transform = CGAffineTransform(scaleX: scale, y: scale)
        }
        
    }
    override func awakeFromNib() {
        let bimage1 = #imageLiteral(resourceName: "icon_building_loading_1")
        let bimage2 = #imageLiteral(resourceName: "icon_building_loading_2")
        buildingIconView.image = UIImage.animatedImage(with: [bimage1,bimage2], duration: 0.5)
        let anim = CABasicAnimation(keyPath:"transform.rotation")
        anim.toValue = -2*M_PI
        anim.repeatCount = MAXFLOAT
        anim.isRemovedOnCompletion = false
        anim.duration = 3
        earthIconView.layer.add(anim, forKey: nil)
        let kimage1 = #imageLiteral(resourceName: "icon_small_kangaroo_loading_1")
        let kimage2 = #imageLiteral(resourceName: "icon_small_kangaroo_loading_2")
        kangarooView.image = UIImage.animatedImage(with: [kimage1,kimage2], duration: 0.5)
        kangarooView.layer.anchorPoint = CGPoint(x: 0.5, y: 1)
        kangarooView.transform = CGAffineTransform(scaleX: 0.2, y: 0.2)
        kangarooView.center = CGPoint(x: self.bounds.width/2, y: self.bounds.height-40)
        
    }
    
}
